package com.mdb.open.epay.validator;

import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.api.enums.ResultCode;
import com.mdb.bc.utils.ObjectUtil;
import com.mdb.open.epay.config.EPayMsgConstant;
import com.mdb.open.epay.domain.dto.epay.SendOtpDto;
import com.mdb.open.epay.enums.type.SmsBizTypeEnum;
import org.springframework.stereotype.Component;

/**
 * otp相關校驗器
 *
 * @author liuyi
 * @date 2019/11/14
 **/
@Component
public class OtpSendParamValidator {

    /**
     * 发送OTP参数校验
     */
    public ResultEx verify(SendOtpDto dto) {
        if (SmsBizTypeEnum.SIGN.getValue().equals(dto.getSmsBizType().getValue())) {
            //發送簽約短信
            if (ObjectUtil.isAnyEmpty(dto.getBankCardNo(), dto.getCertNo(), dto.getCertType())) {
                return ResultEx.makeResult(ResultCode.INVALID_PARAMETER.getValue(), EPayMsgConstant.SEND_SIGN_OTP_PARAM_ERROR);
            }

        } else if (SmsBizTypeEnum.PAY.getValue().equals(dto.getSmsBizType().getValue())) {
            //發送支付短信
            if (ObjectUtil.isAnyEmpty(dto.getOrderNo(), dto.getBankSignNo())) {
                return ResultEx.makeResult(ResultCode.INVALID_PARAMETER.getValue(), EPayMsgConstant.SEND_PAY_OTP_PARAM_ERROR);
            }
        }
        return ResultEx.ok();
    }
}
